<!--商品详情查看页面-->
<template>
  <div >
    <group label-width="4.5em" label-margin-right="2em" label-align="right">
      <x-input title="条形码" v-model="goodInfo.barcode"></x-input>
      <x-input title="名称" v-model="goodInfo.name"></x-input>
    </group>

    <group label-width="4.5em" label-margin-right="2em" label-align="right">
      <x-input title="零售价" v-model="goodInfo.price"></x-input>
      <x-input title="进货价" v-model="goodInfo.purchasing"></x-input>
      <x-input title="批发价" v-model="goodInfo.tradeprice"></x-input>
    </group>

    <group label-width="4.5em" label-margin-right="2em" label-align="right">
      <x-input title="商标" v-model="goodInfo.trademark"></x-input>
      <x-input title="厂商" v-model="goodInfo.manuname"></x-input>
      <x-input title="规格" v-model="goodInfo.spec"></x-input>
      <x-textarea title="商品分类" placeholder="请填写详细商品分类信息" v-model="goodInfo.type" :show-counter="false" :rows="3"></x-textarea>
      <x-textarea title="商品描述" placeholder="请填写详细商品描述信息" v-model="goodInfo.describe" :show-counter="false" :rows="3"></x-textarea>
    </group>
    <div class="weui-cells weui-cells_form">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <div class="weui-uploader">
            <div class="weui-uploader__hd">
              <p class="weui-uploader__title">商品图片</p>
              <div class="weui-uploader__info" >0/9</div>
            </div>
            <div class="weui-uploader__bd">
              <ul class="weui-uploader__files" id="uploaderFiles">
                <li class="weui-uploader__file iosClick previewImage" ></li>
              </ul>
              <div class="weui-uploader__input-box" >
                <span id="uploaderInput" class="weui-uploader__input chooseImg"></span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <toast v-model="toast.show" :type="toast.type" :text="toast.text" :position="toast.position"></toast>
    <Loading v-model="transition"></Loading>

  </div>
</template>

<script>
  import { Group, Cell, XInput, Selector, PopupPicker, Datetime, XNumber, XAddress, XTextarea, Toast, Tabbar, Loading } from 'vux'
  import { webHttp, galaxy } from '@/galaxy/index.js'

  export default {
    components: {
      Group,
      Cell,
      XInput,
      Selector,
      PopupPicker,
      XAddress,
      Datetime,
      XNumber,
      XTextarea,
      Toast,
      Tabbar,
      Loading
    },
    data () {
      return {
        transition: true,
        goodInfo: {
          barcode: this.$route.params.id,
          describe: '',
          spec: '',
          img: [],
          barcodeimg: '',
          type: '',
          trademark: '',
          name: '',
          manuname: '',
          price: '',
          purchasing: '',
          tradeprice: ''
        },
        toast: {
          text: '错误',
          show: false,
          type: 'cancel',
          position: ''
        }
      }
    },
    created () {
      this.search()
    },
    methods: {
      search: function () {
        let _this = this;
        webHttp.post('/goods/searchGoodsByCode', {
          'code': this.$route.params.id
        }).then(function (response) {
          if (response && response.data && response.data.code === '200') {
            let data = response.data.result;
            if (data) {
              _this.goodInfo.barcode = data.barcode;
              _this.goodInfo.barcodeimg = data.barcodeimg;
              _this.goodInfo.describe = data.describe;
              _this.goodInfo.manuname = data.manuname;
              _this.goodInfo.name = data.name;
              _this.goodInfo.price = data.price;
              _this.goodInfo.purchasing = data.purchasing;
              _this.goodInfo.spec = data.spec;
              _this.goodInfo.trademark = data.trademark;
              _this.goodInfo.tradeprice = data.tradeprice;
              _this.goodInfo.type = data.type;

              let img = data.img;
              if (img) {
                  let imgInfo = JSON.parse(img);
                  for (var i = 0; i < imgInfo.length; i++) {
                      imgInfo[i].imgPath = galaxy.BaseURL + '/images/' + imgInfo[i].imgPath
                  }
                  _this.goodInfo.img = imgInfo
              }

              galaxy.setTitle(data.name)
            }
          }
          _this.transition = false
        }).catch(function () {
          _this.transition = false
        })
      }
    }
  }
</script>

<style>
  .weui-tabbar{
    position:fixed;
  }
</style>
